﻿@model ResetPasswordViewModel
@{
    ViewData["Title"] = "重设密码";
    Layout = "_LayoutBlank";
}

<div class="account-pages mt-5 mb-5">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8 col-lg-6 col-xl-5">
                <div class="card bg-pattern">

                    <div class="card-body p-4">

                        <div class="text-center w-75 m-auto">
                            <a href="index.html">
                                <span><img src="/assets/images/logo-light.png" alt="" height="116"></span>
                            </a>
                            <p class="text-muted mb-1 mt-1">重设密码</p>
                        </div>

                        <form asp-route-returnUrl="@ViewData["ReturnUrl"]" method="post">

                            <div class="form-group">
                                <label asp-for="UserName">用户名</label>
                                <input asp-for="UserName" class="form-control" type="text" placeholder="输入您的用户名">
                                <span asp-validation-for="UserName" class="text-danger"></span>
                            </div>

                            <div class="form-group">
                                <label asp-for="Password"></label>
                                <input class="form-control" type="password" asp-for="Password" id="password" placeholder="密码">
                                <span asp-validation-for="Password" class="text-danger"></span>
                            </div>

                            <div class="form-group">
                                <label asp-for="ConfirmPassword"></label>
                                <input class="form-control" type="password" asp-for="ConfirmPassword" id="password" placeholder="确认密码">
                                <span asp-validation-for="ConfirmPassword" class="text-danger"></span>
                            </div>

                            <div class="form-group">
                                <label asp-for="ValidationCode"></label>
                                <div style="display:inline-flex">
                                    <div>
                                        <input asp-for="ValidationCode" class="form-control" placeholder="验证码" />
                                        <span asp-validation-for="ValidationCode" class="text-danger"></span>
                                    </div>
                                    <input type="button" value="获取验证码" id="sendcode" style="margin-left: 20px" class="btn btn-primary btn-block btn-flat" />
                                </div>

                            </div>

                            <div class="form-group mb-0 text-center">
                                <button class="btn btn-info btn-block" type="submit"> 重设密码 </button>
                            </div>

                        </form>



                    </div> <!-- end card-body -->
                </div>
                <!-- end card -->
                <!-- end row -->

            </div> <!-- end col -->
        </div>
        <!-- end row -->
    </div>
    <!-- end container -->
</div>






@section Scripts {
    @await Html.PartialAsync("_ValidationScriptsPartial")
    <script>

        var err = $('#error').val();
        if (err) {
            toastr.error(err);
        }

        $(function () {

                var countdown = 60;

                $("#sendcode").click(function () {

                    $.post('@Url.Content("~/api/Account/SendResetPasswordValidationCode")', { data: $("#UserName").val() }, function (data, textStatus, jqXHR) {
                         if (data.success) {
                            ShowMessage(data.message);
                         } else {

                             ShowMessageError(data.message);

                             if (data.message == "您尚未注册平台账号。") {
                                 setTimeout(function () {
                                     window.location.href = '@Url.Content("~/Account/Register")';
                                 },2000)
                             }

                        }
                        //console.log(data);
                    },"json")

                    var i =   setInterval(function () {

                        countdown--;
                        $("#sendcode").attr("disabled", true);     //定时器启动将按钮设置为不可用
                        $("#sendcode").val("重新发送(" + countdown + ")");    //改变button的文本内容

                        if (countdown == 0) {                              //倒计时结束，让按钮能够继续点
                            clearInterval(i);                      //清除定时器
                            $("#sendcode").val("获取验证码");      //此时定时器文本内容为重新获取
                            $("#sendcode").attr("disabled", false);//将按钮重新设好
                            countdown = 60
                        }
                    }, 1000);


                });


            });





    </script>


}
